#include <iostream>
#include <functional>
#include <map>
std::map<char, std::function<int(int, int)>> calculation;
/*函数*/
void print()
{
    std::cout << "hello wrold" << std::endl;
}
int add(int a, int b)
{
    return a + b;
}
class Minus
{
public:
    int operator()(int a, int b)
    {
        return a - b;
    }
};
class Func
{
public:
    int operator()(int a, int b)
    {
        return a - b;
    }
    void print()
    {
        std::cout << "hello wrold\n";
    }
};
int caculate(char symbol, int a, int b)
{
    auto f = calculation[symbol];
    return f(a, b);
}
int devide(int a, int b, int c)
{

    return a / b / c;
}
int main()
{
    /*函数指针调用*/
    // std::function<void()> f = print;

    /*仿函数调用*/
    // func obj;
    // std::function<void()> f = ;

    /*labmda调用*/
    // std::function<void()> f = []()
    // { std::cout << "labmda调用\n"; };
    // f();

    /*状态注册机：用状态去注册函数*/
    // calculation['+'] = add;
    // calculation['-'] = Minus();
    // calculation['*'] = [](int a, int b)
    // {
    //     return a * b;
    // };

    // int res = calulate('*', 2, 3);
    // std::cout << "res = " << res << std::endl;

    Func func; /*成员函数属于特定的对象*/

    auto f = std::bind(&Func::print, &func);/*函数名以及对象名*/
    f();

    /*std::placeholders::_1：占位符，函数原参数*/
    auto d = std::bind(devide, std::placeholders::_1, std::placeholders::_2, 1);
    /*函数格式不匹配*/
    calculation['/'] = d;

    std::cout << caculate('/', 10, 2) << std::endl;

    return 0;
}